﻿function Checkchange(obj) {
    if (document.getElementById("video").checked) {
        document.getElementById("prephoto").style.display = "";
    }
    else {
        document.getElementById("prephoto").style.display = "none";
    }
}

function filereturn() {
    alert("返回");
}
var Upload;
var inte;
var progressObj = new Array();
function fileupload() {
    //            try {
    //                Upload.SetFunc(window, "OnScaned");
    //            }
    //            catch (e) {
    //                alert(e.ToString());
    //            }
    Upload = new ActiveXObject("FileUpManage.FileManageClient");
    try {
        var filepath = document.getElementById("mainupload").value;
        if (filepath == "" || filepath == undefined) {
            alert("请您选择要上传的文件！");
            return false;
        }
        var filetitel = document.getElementById("txttitle").value;
        if (filetitel == "" || filetitel == undefined) {
            alert("请您输入上传的文件的主题！");
            return false;
        }
        var type;
        var prefilepath;
        if (document.getElementById("video").checked) {
            type = "1";
            var extend = filepath.substring(filepath.lastIndexOf(".") + 1).toLocaleLowerCase();
            if (extend != "flv" && extend != "mp4") {
                alert("请选择视频格式为FLV或MP4！");
                return false;
            }
            prefilepath = document.getElementById("preupload").value;
            if (prefilepath == "" || prefilepath == undefined) {
                alert("请您选择视频的预览图片！");
                return false;
            }
            else {
                var extend = prefilepath.substring(prefilepath.lastIndexOf(".") + 1).toLocaleLowerCase();
                if (extend != "jpg" && extend != "bmp" && extend != "gif" && extend != "png") {
                    alert("请选择视频预览图片格式为JPG或BMP或GIF或PNG！");
                    return false;
                }
            }
        }
        else {
            type = "0";
            var extend = filepath.substring(filepath.lastIndexOf(".") + 1).toLocaleLowerCase();
            if (extend != "jpg" && extend != "bmp" && extend != "gif" && extend != "png") {
                alert("请选择图片格式为JPG或BMP或GIF或PNG！");
                return false;
            }
            prefilepath = "";
        }
        inte = self.setInterval("OnScaned()", 1000);
        var username = document.getElementById("username").value;
        var userword = document.getElementById("userword").value;
        $('#uploadfield').block({ message: $('#ui'), css: { width: '800px', border: '#b9dcfe 1px solid', padding: '0.5em 0.2em'} });
        Upload.UploadFile(filepath, type, prefilepath, username, userword, filetitel, window, "OnScaned");
        //alert(Upload.IsUpload);
        //alert(Upload.fileguid);
        //OnScaned();
        //alert(document.getElementById("fileguid").value);
    }
    catch (exception) {
        inte = self.clearInterval(inte);
        $('#uploadfield').unblock();
        alert("上传文件不成功！");
    }
}


function OnScaned() {
    if (Upload.IsUpload) {
        if (!Upload.IsSucceed) {
            try {
                var strprogress = Upload.GetProgress();
                progressObj = strprogress.split("|");
                if (progressObj[1] == "1") {
                    var info = "<FONT color=Green> 当前上传文件:</FONT>" + progressObj[0];
                    info += "<br><FONT color=Green>文件大小:</FONT>" + progressObj[3] + "<FONT color=Green> MB</FONT>";
                    info += "<br><FONT color=Green>已传送大小:</FONT>" + progressObj[4] + "<FONT color=Green> MB</FONT>";
                    info += "<br><FONT color=Green>速度:</FONT>" + progressObj[5] + "<FONT color=Green> KB/S</FONT>";
                    info += "<br><FONT color=Green>剩余时间:</FONT>" + progressObj[6] + "<FONT color=Green> S</FONT>";

                    $("#output").html(info);

                    $("#progressbar").progressbar({ value: 0 }); //初始化
                    $("#progressbar").progressbar("option", "value", parseInt(progressObj[7]));
                    $("#progressbar div").html(parseInt(progressObj[7]).toFixed(2) + "%");
                    $("#progressbar div").addClass("percentText");

                    if (progressObj[2] == "1") {
                        inte = self.clearInterval(inte);
                        $('#uploadfield').unblock();
                        if (Upload.flag == 0) {
                            location = '../Progect/PhotoManage/PhotoProject.aspx?id=' + Upload.fileguid_branch + '&Type=2';
                        }
                        else {
                            location = '../Progect/PhotoManage/VideoProject.aspx?id=' + Upload.fileguid_branch + '&Type=2';
                        }
                    }
                }
            } catch (e) {
                inte = self.clearInterval(inte);
                $('#uploadfield').unblock();
            }
        }
        else {
            inte = self.clearInterval(inte);
            $('#uploadfield').unblock();
            if (Upload.flag == 0) {
                location = '../Progect/PhotoManage/PhotoProject.aspx?id=' + Upload.fileguid_branch + '&Type=2';
            }
            else {
                location = '../Progect/PhotoManage/VideoProject.aspx?id=' + Upload.fileguid_branch + '&Type=2';
            }
        }
    }
    else {
        inte = self.clearInterval(inte);
        $('#uploadfield').unblock();
    }
}

function cancel() {
    Upload.CancelUpload();
    $("#output").html("");
    inte = self.clearInterval(inte);
    $('#uploadfield').unblock();
}

//function titlechange() {
//    document.getElementById("txttitle").value = document.getElementById("txtName").value + document.getElementById("Text1").value + document.getElementById("branchname").value;
//}

function titlechange() {
    var suffix = "";
    if (document.getElementById("checkbranch").checked) {
        suffix += document.getElementById("lblbranch").innerHTML;
    }
    if (document.getElementById("checkdate").checked) {
        suffix += document.getElementById("inputdate").value.replace(/-/g, "");
    }
    document.getElementById("txttitle").value = document.getElementById("txtName").value + document.getElementById("Text1").value + suffix;
}